<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>[[#{orderNo}]]：</label>
                            <input type="text" name="orderNo"/>
                        </li>
                        <li>
                            <label>[[#{logisticsCompany}]]：</label>
                            <input type="text" name="logisticsCompany"/>
                        </li>
                        <li>
                            <label>[[#{trackingNo}]]：</label>
                            <input type="text" name="trackingNumber"/>
                        </li>
                        <li>
                            <label>[[#{paymentTime}]]：</label>
                            <input type="text" class="time-input" id="beginPaymentTime" th:placeholder="#{beginTime}" name="params[beginPaymentTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endPaymentTime" th:placeholder="#{endTime}" name="params[endPaymentTime]" />
                        </li>
                        <li>
                            <label>[[#{orderStatus}]]：</label>
                            <select name="orderStatus" th:with="type=${@dict.getType('jt_order_status')}">
                                <option value="">[[#{all}]]</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>[[#{receiver}]]：</label>
                            <input type="text" name="receiver"/>
                        </li>
                        <li>
                            <label>[[#{contactNumber}]]：</label>
                            <input type="text" name="phoneNumber"/>
                        </li>
                        <li>
                            <label>[[#{region}]]：</label>
                            <input type="text" name="country"/>
                        </li>
                        <li>
                            <label>[[#{detailedAddress}]]：</label>
                            <input type="text" name="fullAddress"/>
                        </li>
                        <li>
                            <label>[[#{buyerRemark}]]：</label>
                            <input type="text" name="buyerRemark"/>
                        </li>
                        <li>
                            <label>[[#{sellerRemark}]]：</label>
                            <input type="text" name="sellerRemark"/>
                        </li>
                        <li>
                            <label>[[#{refundStatus}]]：</label>
                            <select name="refundStatus" th:with="type=${@dict.getType('jt_order_refund_status')}">
                                <option value="">[[#{all}]]</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>[[#{shippingDate}]]：</label>
                            <input type="text" class="time-input" id="beginDvyTime" th:placeholder="#{beginTime}" name="params[beginDvyTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endDvyTime" th:placeholder="#{endTime}" name="params[endDvyTime]" />
                        </li>
                        <li>
                        <li>
                            <label>[[#{createTime}]]：</label>
                            <input type="text" class="time-input" id="beginCreateTime" th:placeholder="#{beginTime}" name="params[beginCreateTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endCreateTime" th:placeholder="#{endTime}" name="params[endCreateTime]" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp; [[#{search}]]</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;[[#{reset}]]</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:order:add">
                <i class="fa fa-plus"></i> [[#{addOrder}]]
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="business:order:edit">
                <i class="fa fa-edit"></i> [[#{edit}]]
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:order:remove">
                <i class="fa fa-remove"></i> [[#{cancel}]]
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:order:export">
                <i class="fa fa-download"></i> [[#{export}]]
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-fixed-columns-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:order:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:order:remove')}]];
    var deliveryFlag = [[${@permission.hasPermi('business:order:delivery')}]];
    var paymentFlag = [[${@permission.hasPermi('business:order:payment')}]];

    var orderStatusDatas = [[${@dict.getType('jt_order_status')}]];
    var refundStatusDatas = [[${@dict.getType('jt_order_refund_status')}]];
    var prefix = ctx + "business/order";

    $(function() {
        var options = {
            url: prefix + "/list",
            viewUrl: prefix + "/view/{id}",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: i18n("order"),
            fixedColumns: true,
            fixedRightNumber: 1,
            sortName: "createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '订单id',
                    visible: false
                },
                {
                    field: 'buyer',
                    title: i18n("buyer")
                },
                {
                    field: 'orderNo',
                    title: i18n("orderNo"),
                    formatter: function (value, row, index) {
                        return value +'<a href="javascript:void(0)" onclick="$.operate.view(\'' + row.orderId + '\')"><span class="badge badge-info">详</span></a>';
                    }
                },
                {
                    field: 'logisticsCompany',
                    title: i18n("logisticsCompany")
                },
                {
                    field: 'trackingNumber',
                    title: i18n("trackingNo")
                },
                {
                    field: 'buyQty',
                    title: i18n("buyQty")
                },
                {
                    field: 'currency',
                    title: i18n("currency")
                },
                {
                    field: 'freightAmount',
                    title: i18n("shippingFee")
                },
                {
                    field: 'orderAmount',
                    title: i18n("totalAmount")
                },
                {
                    field: 'paymentAmount',
                    title: i18n("paymentAmount")
                },
                {
                    field: 'paymentTime',
                    title: i18n("paymentTime")
                },
                {
                    field: 'orderType',
                    title: i18n("type"),
                    formatter: function(value, row, index) {
                        if(value == 1){
                            return i18n('ordinaryOrder');
                        } else if(value == 2){
                            return i18n('distributorOrder');
                        } else {
                            return value;
                        }
                    }
                },
                {
                    field: 'orderStatus',
                    title: i18n("orderStatus"),
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(orderStatusDatas, value);
                    }
                },
                {
                    field: 'receiver',
                    title: i18n("receiver")
                },
                {
                    field: 'phoneNumber',
                    title: i18n("contactNumber")
                },
                {
                    field: 'country',
                    title: i18n("region")
                },
                {
                    field: 'fullAddress',
                    title: i18n("address")
                },
                {
                    field: 'buyerRemark',
                    title: i18n("buyerRemark")
                },
                {
                    field: 'sellerRemark',
                    title: i18n("sellerRemark")
                },
                {
                    field: 'dvyTime',
                    title: i18n("shippingDate")
                },
                {
                    field: 'finallyTime',
                    title: i18n("finishTime")
                },
                {
                    field: 'refundStatus',
                    title: i18n("refundStatus"),
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(refundStatusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: i18n("createTime"),
                    sortable:true
                },
                {
                    title: i18n("operate"),
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.orderStatus == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.orderId + '\')"><i class="fa fa-edit"></i> '+i18n("edit")+'</a> ');

                            actions.push('<a class="btn btn-info btn-xs ' + paymentFlag + '" href="javascript:void(0)" onclick="doPayment(\'' + row.orderId + '\')"><i class="fa fa-credit-card"></i> '+i18n("payment")+'</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i> '+i18n("cancel")+'</a>');
                        }
                        if(row.orderStatus == 1){
                            actions.push('<a class="btn btn-warning btn-xs ' + deliveryFlag + '" href="javascript:void(0)" onclick="doDelivery(\'' + row.orderId + '\')"><i class="fa fa-codepen"></i> '+i18n("delivery")+'</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function doDelivery(id) {
        var url = prefix + "/delivery/"+id;
        $.modal.open("订单发货", url);
    }


    function doPayment(id) {
        var url = prefix + "/payment/"+id;
        $.modal.open("手工支付订单", url);
    }
</script>

<script th:inline="javascript">
    var ROOT = [[${#servletContext.contextPath}]];
    var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

    //初始化i18n插件
    $.i18n.properties({
        path: ROOT + '/i18n/',//这里表示访问路径
        name: 'messages',//文件名开头
        language: LANG_COUNTRY,//文件名语言 例如en_US
        mode: 'map'//默认值
    });

    function i18n(msgKey) {
        try {
            return $.i18n.prop(msgKey);
        } catch (e) {
            return msgKey;
        }
    }
</script>
</body>
</html>